package com.eastshop.product.action;

import com.eastshop.product.service.ProductService;
import com.eastshop.product.vo.Product;
import com.eastshop.seller.service.SellerService;
import com.eastshop.seller.vo.Seller;
import com.eastshop.utils.PageBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 商品管理的Action
 * 
 * @author admin
 * 
 */
public class ProductAction extends ActionSupport implements
		ModelDriven<Product> {
	// 用于接收数据的模型驱动
	private Product product = new Product();
	// 注入ProductService
	private ProductService productService;

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	// 注入SellerService
	private SellerService sellerService;

	public void setSellerService(SellerService sellerService) {
		this.sellerService = sellerService;
	}

	// 接收分类cid
	private Integer cid;

	public void setCid(Integer cid) {
		this.cid = cid;
	}

	public Integer getCid() {
		return cid;
	}

	// 接收当前page
	private int page;

	public void setPage(int page) {
		this.page = page;
	}

	public Product getModel() {
		return product;
	}

	/**
	 * 根据分类的id分页查询商品
	 * 
	 * @return
	 */
	public String findByCidWithPage() {
		// 分页查询商品信息
		PageBean<Product> pageBean = productService
				.findByCidWithPage(cid, page);
		// 将结果存入值栈中
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		// 查询商家的信息
		Seller seller = sellerService.find();
		// 将结果存入值栈中
		ActionContext.getContext().getValueStack().set("seller", seller);
		return "findByCidWithPage";
	}

	/**
	 * 根据商品id查询商品
	 */
	public String findByPid() {
		product = productService.findByPid(product.getPid());
		// 查询商家的信息
		Seller seller = sellerService.find();
		// 将结果存入值栈中
		ActionContext.getContext().getValueStack().set("seller", seller);
		return "findByPid";
	}
}
